package org.example.xsda.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import org.example.xsda.common.PageResult;
import org.example.xsda.common.Result;
import org.example.xsda.entity.StudentScore;
import org.example.xsda.service.ParentService;
import org.example.xsda.vo.StudentProfileVO;
import org.example.xsda.vo.StudentRecordVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 家长Controller
 * 家长权限：只读 + 导出，不能修改和删除
 */
@RestController
@RequestMapping("/parent")
@SaCheckRole("parent")
public class ParentController {

    @Resource
    private ParentService parentService;

    /**
     * 获取当前家长关联的所有学生（孩子）
     */
    @GetMapping("/children")
    public Result<List<StudentProfileVO>> getMyChildren() {
        List<StudentProfileVO> children = parentService.getMyChildren();
        return Result.success(children);
    }

    /**
     * 获取指定学生的详细档案信息
     */
    @GetMapping("/child/{studentId}")
    public Result<StudentProfileVO> getChildDetail(@PathVariable Long studentId) {
        StudentProfileVO child = parentService.getChildDetail(studentId);
        return Result.success(child);
    }

    /**
     * 获取学生成绩列表（只读）
     */
    @GetMapping("/child/{studentId}/scores")
    public Result<PageResult<StudentScore>> getChildScores(
            @PathVariable Long studentId,
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        PageResult<StudentScore> scores = parentService.getChildScores(studentId, current, size);
        return Result.success(scores);
    }

    /**
     * 获取学生档案记录（只读）
     */
    @GetMapping("/child/{studentId}/records")
    public Result<PageResult<StudentRecordVO>> getChildRecords(
            @PathVariable Long studentId,
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        PageResult<StudentRecordVO> records = parentService.getChildRecords(studentId, current, size);
        return Result.success(records);
    }

    /**
     * 导出学生档案PDF（只读导出）
     */
    @GetMapping("/child/{studentId}/export-pdf")
    public void exportChildProfilePdf(
            @PathVariable Long studentId,
            HttpServletResponse response
    ) {
        parentService.exportChildProfilePdf(studentId, response);
    }

    /**
     * 导出学生成绩Excel（只读导出）
     */
    @GetMapping("/child/{studentId}/export-scores")
    public void exportChildScores(
            @PathVariable Long studentId,
            HttpServletResponse response
    ) {
        parentService.exportChildScores(studentId, response);
    }

    /**
     * 导出学生档案记录Excel（只读导出）
     */
    @GetMapping("/child/{studentId}/export-records")
    public void exportChildRecords(
            @PathVariable Long studentId,
            HttpServletResponse response
    ) {
        parentService.exportChildRecords(studentId, response);
    }
}

